package com.leetcode.array;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class SubSets1 {

	public static void main(String[] args) {
		int[] nums={1,2,3,4};
		List<List<Integer>> subsetList=subsets(nums);
		Iterator<List<Integer>> it=subsetList.iterator();
		while(it.hasNext()){
			System.out.println(it.next());
		}
	}
	public static List<List<Integer>> subsets(int[] nums) {
		  List<List<Integer>> result = new ArrayList<List<Integer>>();
	        if(nums == null || nums.length==0) return result;
	        subsetR(nums,nums.length-1,result);
	        return result;
	    }
	    
	    private static void subsetR(int[] nums, int i, List<List<Integer>> result) {
	        
	        if(i<0) {
	            result.add(new ArrayList<Integer>());
	            return;
	        }
	        
	        subsetR(nums,i-1,result);
	        int size = result.size();
	        for(int j = 0; j <size ; j++) {
	            List<Integer> newList = new ArrayList<Integer>();
	            newList.addAll(result.get(j));
	            newList.add(nums[i]);
	            result.add(newList);
	        }
	        
	    }

}
